/**
 * SettingsPane.java
 * A frame of changeable program settings.
 * 
 * Copyright (c) 2012 The Javanauts
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this 
 * software and associated documentation files (the "Software"), to deal in the Software 
 * without restriction, including without limitation the rights to use, copy, modify, 
 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
 * persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package edu.utsa.cs.cs4953_2012.abacus;

import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.EmptyBorder;

import edu.utsa.cs.cs4953_2012.abacus.Settings.Mode;

/**
 * Lets the user change the program settings.
 *
 */
public class SettingsPane extends JFrame {
	/**
	 * Included because JFrame implements the Serializable interface.
	 */
	private static final long serialVersionUID = 3368918122632941567L;

	/**
	 * Default Constructor.
	 */
	public SettingsPane () {
		
		setTitle("Settings");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		JPanel contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
		
		// Switch between addition mode and multiplication mode
		JRadioButton addLayout   = new JRadioButton("Addition"  , true);
		addLayout.addActionListener(new MenuHandler());
		addLayout.setSelected(Settings.mode == Mode.NORMAL);
		JRadioButton multLayout    = new JRadioButton("Multiplication"   , false);
		multLayout.addActionListener(new MenuHandler());
		multLayout.setSelected(Settings.mode == Mode.SPLIT);

		ButtonGroup layoutToggleGroup = new ButtonGroup();
		layoutToggleGroup.add(addLayout);
		layoutToggleGroup.add(multLayout);

		JPanel layoutTogglePane = new JPanel();
		layoutTogglePane.setLayout(new GridLayout(1, 2));
		layoutTogglePane.add(addLayout);
		layoutTogglePane.add(multLayout);

		layoutTogglePane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Layout"));
		
		contentPane.add(layoutTogglePane);
		
		
		// Toggle showing Arabic digits
		JCheckBox mayanOn   = new JCheckBox("Mayan Numerals");
		mayanOn.addActionListener(new MenuHandler());
		mayanOn.setSelected(Settings.mayaPanel.isVisible());
		mayanOn.setActionCommand("Toggle Mayan Numerals");
		JCheckBox decimalOn    = new JCheckBox("Decimal Numerals");
		decimalOn.addActionListener(new MenuHandler());
		decimalOn.setSelected(Settings.statusPanel.isVisible());
		decimalOn.setActionCommand("Toggle Decimal Numerals");

		JPanel numeralTogglePane = new JPanel();
		numeralTogglePane.setLayout(new GridLayout(1, 2));
		numeralTogglePane.add(decimalOn);
		numeralTogglePane.add(mayanOn);

		numeralTogglePane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Numeral Display"));
		contentPane.add(numeralTogglePane);
		
		// Switch between addition mode and multiplication mode
		JRadioButton oldBeads = new JRadioButton("Plain Beads", true);
		oldBeads.addActionListener(new MenuHandler());
		oldBeads.setSelected(Settings.currentBeadSet == 0);
		JRadioButton newBeads = new JRadioButton("Fancy Beads", false);
		newBeads.addActionListener(new MenuHandler());
		newBeads.setSelected(Settings.currentBeadSet == 1);

		layoutToggleGroup = new ButtonGroup();
		layoutToggleGroup.add(oldBeads);
		layoutToggleGroup.add(newBeads);

		layoutTogglePane = new JPanel();
		layoutTogglePane.setLayout(new GridLayout(1, 2));
		layoutTogglePane.add(oldBeads);
		layoutTogglePane.add(newBeads);

		layoutTogglePane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Bead Set Type"));
		contentPane.add(layoutTogglePane);
		 
		pack();
	}
}
